<?php

namespace App\Service\Message\v1_2_7;

use App\Constants\ErrorCode;
use App\Model\CloseFriend;
use App\Model\User;
use App\Model\UserProfile;
use App\Service\User\UserBaseService;

/**
 * 聊友标签
 */
class MsgTagsService extends UserBaseService
{
    protected function RoVerifyList()
    {
        return [
            'im_accounts' => 'required|string'
        ];
    }

    public function handle()
    {
        $userId = $this->getUserId();
        $imAccounts = $this->request->input('im_accounts', '');
        $imAccounts = explode(',', $imAccounts);
        $imAccounts = array_slice($imAccounts, 0, 100);
        $userIds = User::getUserIdByIm($imAccounts, 'im_kv');
        $users = UserProfile::getUsersProfile(array_keys($userIds));
        $ret['list'] = [];
        // array_walk($users, function ($user) use (&$ret, $userIds) {

        // });
        $tags = $this->getTags();
        $ret = ['list' => []];
        foreach ($imAccounts as $account) {
            $ret['list'][] = [
                'im_account' => $account,
                'tags' => $tags[array_rand($tags)]
            ];
        }
        return $ret;
    }

    function getTags()
    {
        return [
            1 => ['tag_id' => 1, 'tag_name' => '视频过'],
            ['tag_id' => 2, 'tag_name' => '互动过'],
            ['tag_id' => 3, 'tag_name' => '语音过'],
            ['tag_id' => 4, 'tag_name' => '同城'],
        ];
    }
}
